//
//  Command.m
//  Command
//
//  Created by Hechun on 2020/11/7.
//

#import "Command.h"

#import "CommandManager.h"

@implementation Command

- (void)execute {
    // override to subclass
    
    [self done];
}

- (void)cancel {
    self.completion = nil;
}

- (void)done {
    // 异步回到主队列,通知调用方
    dispatch_async(dispatch_get_main_queue(), ^{
        if (self.completion) {
            self.completion(self);
        }
        
        // 释放
        self.completion = nil;
        
        [[CommandManager synchronizedManager].arrayCommands removeObject:self];
    });
}

@end
